-
Notifications
You must be signed in to change notification settings - Fork 997
Seeed WioTerminal support #1124
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
src/machine/board_wioterminal.go
Outdated
| D0 = PB17 // UART0 RX/PWM available | ||
| D1 = PB16 // UART0 TX/PWM available | ||
| D4 = PA14 // PWM available | ||
| D5 = PA16 // PWM available | ||
| D6 = PA18 // PWM available | ||
| D8 = PB03 // built-in neopixel | ||
| D9 = PA19 // PWM available | ||
| D10 = PA20 // can be used for PWM or UART1 TX | ||
| D11 = PA21 // can be used for PWM or UART1 RX | ||
| D12 = PA22 // PWM available | ||
| D13 = PA23 // PWM available | ||
| D21 = PA13 // PWM available | ||
| D22 = PA12 // PWM available | ||
| D23 = PB22 // PWM available | ||
| D24 = PB23 // PWM available | ||
| D25 = PA17 // PWM available |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I could not easily find these in the schematics. Are these pins available on the WioTerminal?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I haven't made it to the correct value yet.
The schematic and pinouts can be found below.
https://files.seeedstudio.com/wiki/Wio-Terminal/res/Wio-Terminal-Schematics.pdf
https://files.seeedstudio.com/wiki/Wio-Terminal/img/WioT-Pinout.jpg
Is the definition of Dxx correct to set D0 to D8 in the Pinout Diagram?
Is it right to fit the Arduino?
Eventually, I'm going to adjust to the following.
https://github.com/Seeed-Studio/ArduinoCore-samd/blob/master/variants/wio_terminal/variant.h
https://github.com/Seeed-Studio/ArduinoCore-samd/blob/master/variants/wio_terminal/variant.cpp
For example.
#define D0 (0ul)
const PinDescription g_APinDescription[0] =
// 0..8 - Raspberry pi Digital & AD pins
{PORTB, 8, PIO_ANALOG, (PIN_ATTR_ANALOG | PIN_ATTR_PWM_E), ADC_Channel2, TC4_CH0, TC4_CH0, EXTERNAL_INT_8}, // 0/RPI_D0/RPI_A0
}I'm going to set it as follows.
D0 = PB08
src/machine/board_wioterminal.go
Outdated
| SPI0_MISO_PIN = PB00 // MISO: SERCOM5/PAD[2] | ||
| ) | ||
|
|
||
| // SPI on the Feather M4. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like you copied this from the Feather M4?
Are you sure that all the definitions in this file are correct for the WioTerminal?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm going to try to get the definition right from now on.
I plan to adjust to the following.
https://github.com/Seeed-Studio/ArduinoCore-samd/blob/master/variants/wio_terminal/variant.h.
https://github.com/Seeed-Studio/ArduinoCore-samd/blob/master/variants/wio_terminal/variant.cpp
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We follow the board markings in TinyGo. If there are no markings on the bard, using the same pin names as Arduino or MicroPython use is fine.
src/machine/machine_atsamd51.go
Outdated
| } | ||
|
|
||
| // Transfer2 writes/reads a single uint16 using the SPI interface. | ||
| func (spi SPI) Transfer2(w uint16) (uint16, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see you have extended the SPI peripheral with 16-bit and 32-bit methods.
- Does this provide an improvement in speed?
- Is this really necessary for WioTerminal support?
I'm asking this, because eventually I would like to switch to DMA and interrupt based SPI transfers. That would make it unnecessary to add Transfer2 and Transfer4 methods, as all the traffic is handled by DMA (which is the fastest possible transfer, except maybe for very short transfers).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this provide an improvement in speed?
Is this really necessary for WioTerminal support?
Yes.
In the demo of pyportal_boing, ILI9341 is too slow at about 10 fps when using Transfer().
Using Transfer2() makes the ILI9341 32 fps and Transfer4() makes it 36 fps.
The processing time excluding DrawRGBBitmap() was 12.5ms, so the time it takes for one DrawRGBBitmap() is as follows
- Transfer : 100 ms
- Transfer2 : 31.25 ms
- Transfer3 : 27.8 ms
Also, I think that DMA should be enabled at some point.
But without a DMA, it's too slow to use Trasnfer4.
So I'd like to enable Transfer4 once, if possible.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You may be able to use a trick like here to improve the speed:
#562
What it does, is that it makes use of double buffering support in the hardware. This makes it possible to continuously stream out data. Maybe the SAM D5x also supports double buffering in the DATA register.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
By using INTEFLAG.DRE, I was able to improve performance without using 32bit-extensions.
ILI9341's pyportal_boing is now 43 fps instead of 36 fps.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ILI9341's pyportal_boing is now 43 fps instead of 36 fps.
I think you possibly meant "36 fps instead of 43 fps" 😸
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The double-buffer-like processing of DRE checks seems to be faster than the 4-byte writes ( the 32B-extensions).
| board | cpu | clock | driver | fps |
|---|---|---|---|---|
| pyportal | samd51j20 | 120Mhz | parallel | 51 fps |
| wioterminal | samd51p19 | 120Mhz | spi (first commit) | 10 fps |
| wioterminal | samd51p19 | 120Mhz | spi with 32B extensions | 36 fps |
| wioterminal | samd51p19 | 120Mhz | spi with DRE check and without 32B extensions | 43 fps |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's a nice improvement! And it should benefit anyone using SPI on the atsamd51.
Can you make a separate PR with those changes?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, now I see you already made the change in tinygo-org/drivers#153.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe the case of just sending (spi.Tx(w, nil)) can be done faster in the same way.
I put that code in ILI9341, but I think it can be done by moving it from spi.go to machine_atsamd51.go (maybe atsamd21 can do it the same way).
|
What should RESET_MAGIC_VALUE be? |
|
The address https://github.com/adafruit/uf2-samdx1/blob/master/inc/uf2.h#L249 is where the original value that we are using comes from. |
|
@sago35 can you please rebase against the |
I think it's probably this. https://github.com/Seeed-Studio/ArduinoCore-samd/blob/master/cores/arduino/Reset.cpp#L59 This meant that no changes were needed. |
|
Since it is the same value for the WioTerminal, no changes needed, you can just use the same value. |
|
@aykevl Maybe I'll change the file below.
|
|
@deadprogram And apart from this PR, I'm working on the following
I'm hoping to make the following as well, but I think it will take some time.
|
|
I tried to write the following, but machine.UART1.handleInterrupt is a private function, so I got an error. error message: func main() {
uart1.Configure(machine.UARTConfig{TX: tx1, RX: rx1})
machine.UART1 = machine.UART{
Buffer: machine.NewRingBuffer(),
Bus: sam.SERCOM2_USART_INT,
SERCOM: 2,
}
machine.UART1.Interrupt = interrupt.New(sam.IRQ_SERCOM2_2, machine.UART1.handleInterrupt) |
|
Hi @sago35 the interrupt handler for the UART would normally be in the Is there a reason to not add the |
|
Hi @deadprogram
This implementation tried to see if it could override the UART1 settings without changing machine_atsamd51.go. I also think that UART is good with machine package at this point. My suggestion is For example, the setting of UART1 needs to be different for each board as follows. itsybitsy-m4 UART1 = UART{
Buffer: NewRingBuffer(),
Bus: sam.SERCOM3_USART_INT,
SERCOM: 3,
}
UART1.Interrupt = interrupt.New(sam.IRQ_SERCOM3_2, UART1.handleInterrupt)wioterminal UART1 = UART{
Buffer: NewRingBuffer(),
Bus: sam.SERCOM2_USART_INT,
SERCOM: 2,
}
UART1.Interrupt = interrupt.New(sam.IRQ_SERCOM2_2, UART1.handleInterrupt) |
|
I think you have the correct idea. Please look at a similar SAMD21 implementation: https://github.com/tinygo-org/tinygo/blob/master/src/machine/board_feather-m0.go#L57-L68 |
|
OK, make SAMD51's UART in the same way. |
|
UART settings have been corrected. I have confirmed that feather-m4 and wioterminal work correctly. |
|
The following are now supported.
|
|
The only thing left to do is to
My source code changes are now complete. |
|
This PR is now complete. |
|
OK @sago35 thanks again for working on this. I have a few ideas on how to split this PR into more easily reviewable/mergable pieces:
Once those are merged, probably the rest of the commits in this current PR can probably then just be squashed into a single PR that is "Add WioTerminal support" What do you think? |
|
I will try to split the PR. |
|
Hi @deadprogram
|
|
Now that #1155 has been merged, this branch needs rebasing to resolve merge conflicts. Thanks! |
|
Hi @deadprogram |
|
Thanks for all of the effort and changes to add this board @sago35 great work! Now squash/merging. Thank you! |
I added Seeed WioTerminal support to TinyGo.
https://wiki.seeedstudio.com/Wio-Terminal-Getting-Started/
ATSAMD5x DataSheet: https://files.seeedstudio.com/wiki/Wio-Terminal/res/ATSAMD51.pdf
PinOut: https://files.seeedstudio.com/wiki/Wio-Terminal/img/WioT-Pinout.jpg
Schematics: https://files.seeedstudio.com/wiki/Wio-Terminal/res/Wio-Terminal-Schematics.pdf
Current Status:
status
not for this PRIt wasn't implemented on the board.TODO